/**
 * Copyright: marvy 2007-3-20<br>
 * 
 * @author marvy
 */
package tailorbird.util.security;

import java.util.Arrays;

/**
 * @author marvy
 */
public class JCEUtil {

	public static void adjustDESParity(byte[] bytes) {

		for (int i = 0; i < bytes.length; i++) {
			int b = bytes[i];
			bytes[i] = (byte) ((b & 0xfe) | ((((b >> 1) ^ (b >> 2) ^ (b >> 3)
					^ (b >> 4) ^ (b >> 5) ^ (b >> 6) ^ (b >> 7)) ^ 0x01) & 0x01));
		}
	}

	public static boolean isDESParityAdjusted(byte[] bytes) {

		byte[] correct = (byte[]) bytes.clone();
		adjustDESParity(correct);
		return Arrays.equals(bytes, correct);
	}

	private JCEUtil() {

	}

}
